package github.sf.fw.tools.db.catalog.doris;

import github.sf.fw.tools.db.catalog.Fragment;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 分区
 *
 * @author zhoup
 * @since 2023/7/26
 */
@Data
public class DistributedModel implements Fragment {
    private final static String keyword = "DISTRIBUTED BY ";
    /**
     * default is hash
     */
    private String distributeMethod = "HASH";

    private String suffix = " BUCKETS 1";

    private List<String> distributedColumns;

    @Override
    public String getFragment() {
        if (distributedColumns == null || distributedColumns.isEmpty()) {
            throw new IllegalArgumentException("distributed 描述的列不能为空");
        }
        String collected = distributedColumns.stream().collect(Collectors.joining(",", "(", ")"));
        return keyword + distributeMethod + collected + suffix;
    }

}
